package es.uned.hoomgle.hibernate.beans.impl;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.search.annotations.Field;

import es.uned.hoomgle.hibernate.beans.interfaces.HomeI;
import es.uned.hoomgle.hibernate.beans.interfaces.UserI;


/**
 * @author  MasterPain
 */
@Entity
public class User implements UserI {
	
	/**
	 * @uml.property  name="id"
	 */
	@Id
	@Column
	@GeneratedValue
	private Integer id;
	/**
	 * @uml.property  name="name"
	 */
	@Column
	@Field
	private String name;
	
	@ManyToMany(cascade = CascadeType.ALL) 
	@JoinTable(name="USER_ROLE",joinColumns=@JoinColumn(name="id_user"),
	inverseJoinColumns=@JoinColumn(name="id_role"))	
	private List<Role> roles;
	
	@Column
	@Field
	private String userName;
	
	@Column
	private String password;
	@Column
	private String email;
	@OneToMany
	(cascade = {CascadeType.ALL})
	private List<Home>homeList;
	
	@Column
	private boolean isActive;

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#getId()
	 */
	@Override
	public Integer getId() {		
		return id;
	}

	
	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setId(java.lang.Integer)
	 */
	@Override
	public void setId(Integer id) {
		this.id = id;
	}


	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setName(java.lang.String)
	 */
	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	
	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#getUserName()
	 */
	@Override
	public String getUserName() {
		return userName;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setUserName(java.lang.String)
	 */
	@Override
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#getPassword()
	 */
	@Override
	public String getPassword() {
		return password;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setPassword(java.lang.String)
	 */
	@Override
	public void setPassword(String password) {
		this.password = password;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#getEmail)
	 */ 
	@Override
	public String getEmail() {
		return this.email;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setEmail(java.lang.String)
	 */ 
	@Override
	public void setEmail(String email) {
		this.email = email;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#isActive()
	 */
	@Override
	public boolean isActive() {
		return isActive;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.UserI#setActive(boolean)
	 */
	@Override
	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}
	
	

	public List getRoles() {
		return roles;
	}


	public void setRoles(List roles) {
		this.roles = roles;
	}

	

	public List getHomeList() {
		return homeList;
	}


	public void setHomeList(List homeList) {
		this.homeList = homeList;
	}


	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("User [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", userName=");
		builder.append(userName);
		builder.append(", password=");
		builder.append(password);
		builder.append(", e-mail=");
		builder.append(email);
		builder.append(", isActive=");
		builder.append(isActive);
		builder.append("]");
		return builder.toString();
	}

	
	
	
	
	
}



